//
//  MoreViewController.m
//  specialine
//
//  Created by 往返网络 on 17/7/11.
//  Copyright © 2017年 com. All rights reserved.
//

#import "MoreViewController.h" //交易记录
#import "MoreTableViewCell.h"
#import "HYCalendarViewController.h"
#define return_tag  2000
#define search_tag  2001
#define minbegin_x 24.0/W_BASE*SCREEN_W
//定义交易记录URL
#define URL_JILU [NSString stringWithFormat:@"%@/Appcustomernewer/Pay/getAccountLog?type=get",BASE_URL]
@interface MoreViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UIScrollView * searchview; //搜索view
@property (nonatomic,strong)UIView * backview; //透明背景
@property (nonatomic, strong) NSArray * firstDate;//第一个时间
@property (nonatomic, strong) NSArray * lastDate;//第二个时间
@property (nonatomic,copy)NSString * time; //搜索的time
@property (nonatomic,copy)NSString * startime;
@property (nonatomic,copy)NSString * endtime;
@property (nonatomic,assign)BOOL status_click; //状态btn有没有被点击
@property (nonatomic,copy)NSString* current_tag;//当前搜索状态选择
@property (nonatomic,strong)AFHTTPSessionManager* manger;
@property (nonatomic,strong)NSMutableArray * datasource;
@end
@implementation MoreViewController

{
    
    UILabel * shourulab;//总收入
    UILabel * zhichulab;//总支出
    UITableView * tableview;
    UIView * statusview; //状态view
    UIButton * totalbtn; //充值
    UIButton * yirukubtn; //提现
    UIButton * yichukubtn; //转账
    UIView * kaidandateview; //日期
    UIButton * startTiming; //起始日期
    UIButton * endTiming; //终止日期
    UIImageView * image; //状态上的图片
    NSInteger  page; //当前页面
    NSInteger  totalPage; //总页数
    NSString * type; //操作类型 1、充值 2、提现 3、转账，空代表查全部
    NSString *  pageSize; //每页条数
    
}
- (void)viewDidLoad {
    
    [super viewDidLoad];
    //初始化数据参数
    page = 1;
    pageSize = @"10";
    self.time = @"";
    type = @"";
    [self loadData]; //请求全部数据
    [self createUI];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    
}
- (void)viewWillDisappear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = NO;
}
- (void)loadData{
    
    NSUserDefaults * userdefalut = [NSUserDefaults standardUserDefaults];
    
    NSString *  token = [userdefalut objectForKey:USER_TOCKE];
    
    page = 1;
    
    NSString * url = [NSString stringWithFormat:@"%@&token=%@&pageSize=%@&currentPage=%ld&time=%@&type=%@",URL_JILU,token,pageSize,page,self.time,type];
    //有中文搜索，需要转码
    NSString * URL  = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"交易记录 url %@",url);
    [self.manger GET:URL parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject) {
            
            NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
            NSInteger code = [dict[@"code"]integerValue];
            NSDictionary * info = dict[@"info"];
            totalPage = [info[@"totalPage"]integerValue];
            NSLog(@"totolpage %ld",totalPage);

            if (code == 0) {
                //清除原有数据
                [self.datasource removeAllObjects];
                NSArray * datarr = info[@"data"];
                NSLog(@"datarr count %ld",datarr.count);
                for (NSDictionary * data in datarr) {
                    NSLog(@"交易号id %@",data[@"id"]);
                    [self.datasource addObject:data];
                }
                
                //刷新tableview
                [tableview reloadData];
                [tableview.header endRefreshing];
                
            }else{
                
                [tableview.header endRefreshing];
                ALERT(@"提示", dict[@"info"], self, @"确定", nil);
                
            }
            
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        [tableview.header endRefreshing];
        
        ALERT(@"提示", @"网络请求失败", self, @"确定", nil);
        
    }];
    
    
}

- (void)loadMoredata{

    
    NSUserDefaults * userdefalut = [NSUserDefaults standardUserDefaults];
    
    NSString *   token = [userdefalut objectForKey:USER_TOCKE];
    
    NSString * url = [NSString stringWithFormat:@"%@&token=%@&pageSize=%@&currentPage=%ld&time=%@&type=%@",URL_JILU,token,pageSize,page+1,self.time,type];
    
    //有中文搜索，需要转码
    NSString * URL  = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSLog(@"more url %@",url);
    
    [self.manger GET:URL parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject) {
            
            NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
            NSInteger code = [dict[@"code"]integerValue];
            
            NSDictionary * info = dict[@"info"];

            if (code == 0) {
                
                NSArray * datarr = info[@"data"];
                NSLog(@"datarr count %ld",datarr.count);

                for (NSDictionary * data in datarr) {
                    NSLog(@"交易号id %@",data[@"id"]);
                [self.datasource addObject:data];
                    
                }
                
                page++;
                //刷新tableview
                [tableview reloadData];
                [tableview.footer endRefreshing];
                
            }else {
                
                if (page == totalPage) {
                    [tableview.footer endRefreshing];
                }
                else{
                    [tableview.footer endRefreshing];
                    ALERT(@"提示", dict[@"info"], self, @"确定", nil);
                    
                }
            }
            
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
        [tableview.footer endRefreshing];
        
        ALERT(@"提示", @"网络请求失败", self, @"确定", nil);
        
    }];
    
    
}
- (void)createUI{
    
        self.view.backgroundColor = [UIColor whiteColor];
    
        self.view.backgroundColor = [UIColor whiteColor];
        float fontsize = 17;
        fontsize = SCREEN_H < 667 ? 15 : 19;
        
        if (SCREEN_H == 667) {
            
            fontsize = 17;
        }
       self.view.backgroundColor = COLORRGBA(239, 239, 239, 1);
       UIView * titleview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 128.0/1334*SCREEN_H)];
    
       titleview.backgroundColor = COLORRGBA(7, 24, 57, 1);
    
       [self.view addSubview:titleview];
    
        //title
        UILabel * titlelab = [[UILabel alloc]initWithFrame:CGRectMake(0, 20.0, SCREEN_W, 90.0/H_BASE*SCREEN_H)];
        titlelab.text = @"交易记录";
        
        titlelab.textColor = [UIColor whiteColor];
        
        [self.view addSubview:titlelab];
        
        titlelab.textAlignment = NSTextAlignmentCenter;
        
        titlelab.font = [UIFont systemFontOfSize:fontsize];
        
        UILabel * leftlable  = [[UILabel alloc]initWithFrame:CGRectMake(0, 20+14.0/1334*SCREEN_H, 150.0/W_BASE*SCREEN_W, 60.0/1334.0*SCREEN_H)];
        leftlable.textAlignment = NSTextAlignmentCenter;
        NSString * endstr = @"\U0000e697";
        NSString * text = [NSString stringWithFormat:@"%@%@",endstr,@"返回"];
        leftlable.attributedText = [self changeLabelWithText2:text andStartplace:endstr andendplae:nil andfontsize:fontsize-2];
        leftlable.textColor = [UIColor whiteColor];
        [self.view addSubview:leftlable];
        
        UIButton * returnbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 150.0/W_BASE*SCREEN_W, 150.0/H_BASE*SCREEN_H)];
        [returnbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
        returnbtn.tag = return_tag;
        [self.view addSubview:returnbtn];
        
        UIButton * morebtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_W - 120.0/W_BASE*SCREEN_W,20+14.0/1334*SCREEN_H ,120.0/W_BASE*SCREEN_W, 60.0/H_BASE*SCREEN_H)];
        [morebtn setTitle:@"搜索" forState:UIControlStateNormal];
        [morebtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
        [morebtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.view addSubview:morebtn];
        morebtn.tag = search_tag;
        morebtn.titleLabel.font = [UIFont systemFontOfSize:fontsize - 2];
    
//    UIView * shouruview = [[UIView alloc]initWithFrame:CGRectMake(0, 127.0/H_BASE*SCREEN_H, SCREEN_W, SCREEN_H-127.0/H_BASE*SCREEN_H)];
//    shouruview.backgroundColor = COLORRGBA(239, 239, 239, 1);
//    [self.view addSubview:shouruview];
//    UILabel * sumshouru = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 212.0/W_BASE*SCREEN_W, 129.0/H_BASE*SCREEN_H)];
//    sumshouru.text = @"总收入(元):";
//    sumshouru.textColor = [UIColor blackColor];
//    [shouruview addSubview:sumshouru];
//    sumshouru.font = [UIFont systemFontOfSize:fontsize -4];
//    sumshouru.textAlignment = NSTextAlignmentRight;
//    
//    shourulab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(sumshouru.frame)+8.0/W_BASE*SCREEN_W, 0, 193.0/W_BASE*SCREEN_W, CGRectGetHeight(sumshouru.frame))];
//    shourulab.textColor = COLORRGBA(47, 165, 255, 1);
//    [shouruview addSubview:shourulab];
//    shourulab.font = [UIFont systemFontOfSize:fontsize - 4];
//    shourulab.text = @"+2000";
//    
//    UILabel * zhichu = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(shourulab.frame), 0, 136.0/W_BASE*SCREEN_W, CGRectGetHeight(shourulab.frame))];
//    zhichu.text = @"总支出(元):";
//    zhichu.textColor = [UIColor blackColor];
//    [shouruview addSubview:zhichu];
//    zhichu.font = [UIFont systemFontOfSize:fontsize -4];
//    zhichu.textAlignment = NSTextAlignmentRight;
//    zhichulab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(zhichu.frame)+8.0/W_BASE*SCREEN_W, 0, 194.0/W_BASE*SCREEN_W, CGRectGetHeight(zhichu.frame))];
//    zhichulab.textColor = COLORRGBA(255, 102, 102, 1);
//    zhichulab.text = @"-2000";
//    zhichulab.font = [UIFont systemFontOfSize:fontsize -4];
//    zhichulab.textAlignment = NSTextAlignmentLeft;
//    [shouruview addSubview:zhichulab];
    
    tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(titleview.frame), SCREEN_W, SCREEN_H-CGRectGetHeight(titleview.frame)) style:UITableViewStylePlain];
    tableview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:tableview];
    [tableview registerClass:[MoreTableViewCell class] forCellReuseIdentifier:@"cell"];
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    //设置MJRefresh
    MJRefreshNormalHeader* header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self loadData];
        
    }];
    
    [header setTitle:@"努力加载中 ..." forState:MJRefreshStatePulling];
    [header setTitle:@"正在刷新" forState:MJRefreshStateRefreshing];
    
    tableview.header = header;
    MJRefreshBackNormalFooter * footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        
        [self loadMoredata];
        
    }];
    
    [footer setTitle:@"加载更多" forState:MJRefreshStatePulling];
    
    [footer setTitle:@"正在加载" forState:MJRefreshStateRefreshing];
    
    tableview.footer = footer;
    [self createSearchView]; //搜索view
    
}
#pragma mark  -  -  起始地＋发货人名（终止地＋收货人名）格式化 － － －-- - -  -

-(NSMutableAttributedString*) changeLabelWithText2:(NSString*)needText andStartplace:(NSString *)startplace andendplae:(NSString *)endplace andfontsize:(float)fontsize
{
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:needText];
    NSInteger startlength = startplace.length;
    //起始格式化
    [attrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"iconfont" size:fontsize+2] range:NSMakeRange(0,startlength)];
    //    //尾部格式化
    [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:fontsize] range:NSMakeRange(startlength , needText.length  - startlength)];
    return attrString;
}

#pragma mark - - - -  - - - - - - - -- -  - - - 创建搜索试图 - - -  - - - - -- - -  -

- (void)createSearchView{
    
    float fontsize = 14;
    
    fontsize = SCREEN_H< 667 ? 12 : 16;
    
    if (fontsize == 667) {
        
        fontsize = 14;
        
    }
    
    _backview = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_W, 0, 90.0/W_BASE*SCREEN_W, SCREEN_H)];
    _backview.backgroundColor = COLORRGBA(150, 150, 150, 0.25);
    
    //添加手势，点击空白处，searchview消失
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
    
    [_backview addGestureRecognizer:tap];
    
    [self.view addSubview:_backview];
    
    _searchview = [[UIScrollView alloc]initWithFrame:CGRectMake(SCREEN_W+90.0/W_BASE*SCREEN_W, 0, SCREEN_W - 90.0/W_BASE*SCREEN_W, SCREEN_H)];
    _searchview.backgroundColor = [UIColor whiteColor];
    _searchview.contentSize = CGSizeMake(SCREEN_W - 90.0/W_BASE*SCREEN_W, 1000.0/H_BASE*SCREEN_H);
    _searchview.delegate = self;
    //    _searchview.showsVerticalScrollIndicator = NO;
    //    _searchview.showsHorizontalScrollIndicator = NO;
    _searchview.pagingEnabled = NO;
    
    //贴在window上将视图置于最前面,盖住navigationbar /tabbar
    
    [self.view addSubview:_searchview];
    
    
    //创建开单日期
    kaidandateview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(_searchview.frame), 208.0/H_BASE*SCREEN_H)];
    [_searchview addSubview:kaidandateview];
    
    
    UILabel * kaidanLabel = [[UILabel alloc]initWithFrame:CGRectMake(minbegin_x, 40.0/H_BASE*SCREEN_H, 140.0/W_BASE*SCREEN_W, 77.0/H_BASE*SCREEN_H)];
    kaidanLabel.text = @"日期选择";
    kaidanLabel.textColor = COLORRGBA(153, 153, 153, 1);
    kaidanLabel.font = [UIFont systemFontOfSize:fontsize-1];
    [kaidandateview addSubview:kaidanLabel];
    
    startTiming = [[UIButton alloc] initWithFrame:CGRectMake(35.0/W_BASE*SCREEN_W, CGRectGetMaxY(kaidanLabel.frame), 238.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];
    
    startTiming.layer.cornerRadius = 4;
    
    startTiming.layer.borderWidth = 0.5;
    
    startTiming.layer.borderColor = [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1].CGColor;
    
    [startTiming setTitle:@"起始日期" forState:UIControlStateNormal];
    
    [startTiming setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    startTiming.titleLabel.font = [UIFont systemFontOfSize:fontsize];
    
    [startTiming addTarget:self action:@selector(chooseTime:) forControlEvents:UIControlEventTouchUpInside];
    
    [kaidandateview addSubview:startTiming];
    
    endTiming = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetWidth(_searchview.frame)-35.0/W_BASE*SCREEN_W-238.0/W_BASE*SCREEN_W, CGRectGetMaxY(kaidanLabel.frame), 238.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];
    
    endTiming.layer.cornerRadius = 4;
    
    endTiming.layer.borderWidth = 0.5;
    
    endTiming.layer.borderColor = [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1].CGColor;
    
    endTiming.titleLabel.font = [UIFont systemFontOfSize:fontsize];
    
    [endTiming setTitle:@"结束日期" forState:UIControlStateNormal];
    
    [endTiming setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [endTiming addTarget:self action:@selector(chooseTime:) forControlEvents:UIControlEventTouchUpInside];
    
    [kaidandateview addSubview:endTiming];
    
    UILabel * subLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(startTiming.frame), CGRectGetMinY(endTiming.frame), kaidandateview.frame.size.width - 35.0/W_BASE*SCREEN_W * 2-CGRectGetWidth(startTiming.frame)*2, 70/H_BASE*SCREEN_H)];
    
    subLabel.text = @"至";
    
    subLabel.textColor = COLORRGBA(57, 57, 57, 1);
    
    subLabel.textAlignment = NSTextAlignmentCenter;
    
    subLabel.font = [UIFont systemFontOfSize:fontsize];
    
    [kaidandateview addSubview:subLabel];
    UIView * breakview = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(kaidandateview.frame), SCREEN_W, 1)];
    breakview.backgroundColor = COLORRGBA(239, 239, 239, 1);
    [kaidandateview addSubview:breakview];
    
    //创建状态选择view ----statusview
    statusview = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(breakview.frame), CGRectGetWidth(_searchview.frame), 195.0/H_BASE*SCREEN_H)];
    [_searchview addSubview:statusview];
    
    
    UILabel * statuslabel = [[UILabel alloc]initWithFrame:CGRectMake(minbegin_x, 0, 140.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];
    statuslabel.text = @"类型";
    statuslabel.textColor = COLORRGBA(153, 153, 153, 1);
    statuslabel.font = [UIFont systemFontOfSize:fontsize-1];
    [statusview addSubview:statuslabel];
    
    //创建状态按钮 － －
    
    totalbtn = [[UIButton alloc]initWithFrame:CGRectMake(minbegin_x, CGRectGetMaxY(statuslabel.frame), 183.0/W_BASE*SCREEN_W, 80.0/H_BASE*SCREEN_H)];
    totalbtn.backgroundColor = COLORRGBA(240, 240, 240, 1);
    [totalbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [statusview addSubview:totalbtn];
    totalbtn.titleLabel.font = [UIFont systemFontOfSize:fontsize - 2];
    totalbtn.layer.cornerRadius = 2;
    totalbtn.clipsToBounds = YES;
    [totalbtn setTitle:@"充值" forState:UIControlStateNormal];
    
    yirukubtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(totalbtn.frame)+21.0/W_BASE*SCREEN_W, CGRectGetMaxY(statuslabel.frame), 183.0/W_BASE*SCREEN_W, 80.0/H_BASE*SCREEN_H)];
    yirukubtn.backgroundColor = COLORRGBA(240, 240, 240, 1);
    [yirukubtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [statusview addSubview:yirukubtn];
    yirukubtn.titleLabel.font = [UIFont systemFontOfSize:fontsize - 2];
    yirukubtn.layer.cornerRadius = 2;
    yirukubtn.clipsToBounds = YES;
    [yirukubtn setTitle:@"提现" forState:UIControlStateNormal];
    
    yichukubtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(yirukubtn.frame)+21.0/W_BASE*SCREEN_W, CGRectGetMaxY(statuslabel.frame), 183.0/W_BASE*SCREEN_W, 80.0/H_BASE*SCREEN_H)];
    yichukubtn.backgroundColor = COLORRGBA(240, 240, 240, 1);
    [yichukubtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [statusview addSubview:yichukubtn];
    yichukubtn.titleLabel.font = [UIFont systemFontOfSize:fontsize - 2];
    yichukubtn.layer.cornerRadius = 2;
    yichukubtn.clipsToBounds = YES;
    [yichukubtn setTitle:@"转账" forState:UIControlStateNormal];
    
    totalbtn.tag  = 5001;
    yirukubtn.tag  = 5002;
    yichukubtn.tag = 5003;
    
    [totalbtn addTarget:self action:@selector(statusClick:) forControlEvents:UIControlEventTouchUpInside];
    [yichukubtn addTarget:self action:@selector(statusClick:) forControlEvents:UIControlEventTouchUpInside];
    [yirukubtn addTarget:self action:@selector(statusClick:) forControlEvents:UIControlEventTouchUpInside];
    
    //重置／完成
    //重置／完成
    UIButton * completebtn = [[UIButton alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(_searchview.frame) - 80.0/H_BASE*SCREEN_H, CGRectGetWidth(_searchview.frame)*0.5, 80.0/H_BASE*SCREEN_H)];
    completebtn.backgroundColor = [UIColor whiteColor];
    completebtn.layer.borderColor = [COLORRGBA(204, 204, 204, 1)CGColor];
    completebtn.layer.borderWidth = 1;
    completebtn.clipsToBounds = YES;
    completebtn.titleLabel.font = [UIFont systemFontOfSize:fontsize + 1];
    [_searchview addSubview:completebtn];
    [completebtn setTitle:@"完成" forState:UIControlStateNormal];
    [completebtn setTitleColor:COLORRGBA(204, 204, 204, 1) forState:UIControlStateNormal];
    completebtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    UIButton * resetbtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(completebtn.frame), CGRectGetMinY(completebtn.frame), CGRectGetWidth(completebtn.frame), CGRectGetHeight(completebtn.frame))];
    resetbtn.backgroundColor = COLORRGBA(59, 214, 117, 1);
    [resetbtn setTitle:@"重置" forState:UIControlStateNormal];
    resetbtn.titleLabel.font = [UIFont systemFontOfSize:fontsize+1];
    [_searchview addSubview:resetbtn];
    [resetbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    completebtn.tag = 4000;
    resetbtn.tag = 5000;
    [completebtn addTarget:self action:@selector(enterClick1:) forControlEvents:UIControlEventTouchUpInside];
    [resetbtn addTarget:self action:@selector(enterClick1:) forControlEvents:UIControlEventTouchUpInside];
    
    
}
#pragma mark - - - - - - - - - - -  Action - - - - - - - - - - - - -
- (void)enterClick:(UIButton *)btn{
    
    switch (btn.tag) {
        case return_tag:
            //返回
            [self.navigationController popViewControllerAnimated:YES];
            break;
        case search_tag:
            //搜索
        {
            [self searchUp];
            break;
        }
        default:
            break;
            
    }
}

#pragma mark  -- - - - - --  - - --完成／重置 - - - - -- - - - - - -- - - - - -

- (void)enterClick1:(UIButton *)btn{
    
    switch (btn.tag) {
        case 4000:
            NSLog(@"完成");
            //获得所有搜索值，loadurl //去搜索。。刷新tableview
            //刷新 tableview(发货／到货)
            [self loadData];
            [self searchDown];
            break;
        case 5000:
            NSLog(@"重置");
            //改变专线title,改变line 改变状态btn 清空tf的内容
            for (UIButton * btn in statusview.subviews) {
                if (btn.tag >= 5001) {
                    if (btn.tag == 5001) {
                        [btn setTitle:@"充值" forState:UIControlStateNormal];
                        btn.backgroundColor = COLORRGBA(240, 240, 240, 1);
                        [image removeFromSuperview];
                    }else{
                        btn.hidden = NO;
                    }
                }
            }
            self.time = @"";
            type = @""; //操作类型置空
            [startTiming setTitle:@"起始日期" forState:UIControlStateNormal];
            [endTiming setTitle:@"结束日期" forState:UIControlStateNormal];
            break;
        default:
            break;
    }
    
}

#pragma mark  - - - - -- - - - -- 搜索筛选 状态选择按钮点击事件 － － － － －

- (void)statusClick:(UIButton *)btn{
    
    NSArray * statusarr = @[@"充值",@"提现",@"转账"];
    NSInteger cur_tag = btn.tag;
    if (!self.status_click) {
        for (UIButton * btn in statusview.subviews) {
            if (btn.tag == 5001) {
                //更改第一个按钮的文字
                [btn setTitle:statusarr[cur_tag-1-5000] forState:UIControlStateNormal];
                [btn setBackgroundColor:COLORRGBA(229, 242, 255, 1)];
                //添加图片
                image = [[UIImageView alloc]initWithFrame:CGRectMake(btn.frame.size.width - 35.0/W_BASE*SCREEN_W, btn.frame.size.height - 35.0/W_BASE*SCREEN_W, 35.0/W_BASE*SCREEN_W, 35.0/W_BASE*SCREEN_W)];
                image.image = [UIImage imageNamed:@"statusx"];
                [btn addSubview:image];
                self.current_tag = [NSString stringWithFormat:@"%ld",cur_tag-1-5000];
                NSLog(@"+++++++++++++++++current _tag %@",self.current_tag);
                if ([self.current_tag isEqualToString:@"0"]) {
                    type  = @"1";
                }else if ([self.current_tag isEqualToString:@"1"]){
                type = @"2";
                }else if ([self.current_tag isEqualToString:@"2"]){
                
                type = @"3";
                }
            }else{
                if ([btn isKindOfClass:[UIButton class]]) {
                    btn.hidden = YES;
                    
                }
                
            }
            
        }
        self.status_click = !_status_click;
        
    }else{
        //所有状态btn显示，去除imageview图片,更改current_tag的值
        
        for (UIButton * btn in statusview.subviews) {
            if (btn.tag == 5001) {
                [btn setTitle:@"充值" forState:UIControlStateNormal];
                btn.backgroundColor = COLORRGBA(240, 240, 240, 1);
                [image removeFromSuperview];
            }else{
                btn.hidden = NO;
            }
            
        }
        self.status_click = !_status_click;
        self.current_tag = @""; //更改状态值
        
    }
    
}



#pragma mark  - - -- - - - -- tap backview 搜索页面收起  － －－ － － － －
- (void)tapClick{
    
    [self.view endEditing:YES];
    
    [self searchDown]; //搜索页面收起
    
    
}
#pragma mark  - - -- - - - -- 搜索页面消失动画 - -- - - -

- (void)searchDown{
    
    CGRect rect1 = CGRectMake(SCREEN_W, 0, 90.0/W_BASE*SCREEN_W, SCREEN_H);
    
    _backview.frame = rect1;
    
    [UIView animateWithDuration:0.5 animations:^{
        
        CGRect rect2 = CGRectMake(SCREEN_W+90.0/W_BASE*SCREEN_W, 0, SCREEN_W - 90.0/W_BASE*SCREEN_W, SCREEN_H);
        
        _searchview.frame = rect2;
        
        
    } completion:^(BOOL finished) {
        
    }];
  }

#pragma mark  - - - - -- - - - - 选择开单日期 － － － －－ －

- (void)chooseTime:(UIButton *)btn {
    
    HYCalendarViewController * calendar = [[HYCalendarViewController alloc] init];
    
    UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:calendar];
    
    calendar.itemType = HYCalendarItemTypeRectCollected;
    
    calendar.chooseType = HYCalendarChooseDouble;
    
    calendar.middleColor = [UIColor colorWithRed:67/255.0 green:180/255.0 blue:250/255.0 alpha:1];
    
    calendar.selectedColor = [UIColor blueColor];
    
    calendar.normalColor = [UIColor whiteColor];
    
    //将上次的时间传递回日历中
    calendar.firstDay = self.firstDate;
    
    calendar.lastDay = self.lastDate;
    
    __weak MoreViewController * weakSelf = self;
    calendar.getTime = ^(NSArray * firstDay, NSArray * lastDay){
        
        NSInteger firstTime = [firstDay[0] integerValue] * 12 + [firstDay[1] integerValue] * 31 + [firstDay[2] integerValue];
        NSInteger lastTime = [lastDay[0] integerValue] * 12 + [lastDay[1] integerValue] * 31 + [lastDay[2] integerValue];
        
        //时间文字方向
        NSString * startTitle;
        NSString * endTitle;
        startTitle = firstTime < lastTime ? [NSString stringWithFormat:@"%ld-%02ld-%02ld", (long)[firstDay[0] integerValue], (long)[firstDay[1] integerValue], (long)[firstDay[2] integerValue]] : [NSString stringWithFormat:@"%ld-%02ld-%02ld",(long)[lastDay[0] integerValue], (long)[lastDay[1] integerValue], (long)[lastDay[2] integerValue]];
        endTitle = firstTime > lastTime ? [NSString stringWithFormat:@"%ld-%02ld-%02ld", (long)[firstDay[0] integerValue], (long)[firstDay[1] integerValue], (long)[firstDay[2] integerValue]] : [NSString stringWithFormat:@"%ld-%02ld-%02ld",(long)[lastDay[0] integerValue], (long)[lastDay[1] integerValue], (long)[lastDay[2] integerValue]];;
        
        [startTiming setTitle:startTitle forState:UIControlStateNormal];
        [endTiming setTitle:endTitle forState:UIControlStateNormal];
        
        
        
        weakSelf.time = [NSString stringWithFormat:@"%@~%@",startTitle,endTitle];
        
        weakSelf.firstDate = firstDay;
        
        weakSelf.lastDate = lastDay;
        
        NSLog(@"time is %@",weakSelf.time);
        weakSelf.time = [NSString stringWithFormat:@"%@~%@",startTitle,endTitle];
        weakSelf.startime = startTitle;
        weakSelf.endtime = endTitle;

//        if ([self.search_type isEqualToString:@"1"]) {
//            weakSelf.time = [NSString stringWithFormat:@"%@~%@",startTitle,endTitle];
//            weakSelf.startime = startTitle;
//            weakSelf.endtime = endTitle;
//        }else{
//            weakSelf.time1 = [NSString stringWithFormat:@"%@~%@",startTitle,endTitle];
//            weakSelf.startime1 = startTitle;
//            weakSelf.endtime1 = endTitle;
//            
//        }
        
    };
    
    
    [self presentViewController:navi animated:YES completion:nil];
    
}

#pragma mark -   - -- - - - 搜索页面弹出 动画- - - -- - -

- (void)searchUp{
    
    
    //搜索页面弹出
    [UIView animateWithDuration:0.5 animations:^{
        
        CGRect rect2 = CGRectMake(90.0/W_BASE*SCREEN_W, 0, SCREEN_W - 90.0/W_BASE*SCREEN_W, SCREEN_H);
        
        _searchview.frame = rect2;
        
        //改变专线title,改变line 改变状态btn 清空tf的内容
//        linelabel.text = @"专线选择";
//        self.lineid = @"";
        for (UIButton * btn in statusview.subviews) {
            if (btn.tag >= 5001) {
                if (btn.tag == 5001) {
                    [btn setTitle:@"充值" forState:UIControlStateNormal];
                    btn.backgroundColor = COLORRGBA(240, 240, 240, 1);
                    [image removeFromSuperview];
                    
                }else{
                    btn.hidden = NO;
                }
                
            }
            
        }
        
//        self.kandanren = @"";
//        self.shouhuoren = @"";
//        self.fahuoren = @"";
//        self.mudidi = @"";
//        self.yundanid = @"";
//        self.time = @"";
//        kandanrentf.text = @"";
//        shouhuotf.text = @"";
//        fahuotf.text = @"";
//        muditf.text = @"";
//        yundanidtf.text = @"";
        [startTiming setTitle:@"起始日期" forState:UIControlStateNormal];
        [endTiming setTitle:@"结束日期" forState:UIControlStateNormal];
        
        
    } completion:^(BOOL finished) {
        
        
        CGRect rect1 = CGRectMake(0, 0, 90.0/W_BASE*SCREEN_W, SCREEN_H);
        
        _backview.frame = rect1;
        
    }];
    
}

#pragma mark - - - - --  -- -- textfield Delegate -  - -- - - - - - - - -
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 107.0/H_BASE*SCREEN_H;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.datasource.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    MoreTableViewCell * cell = [tableview dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.userInteractionEnabled = NO;
    NSDictionary * dict = self.datasource[indexPath.row];
    [cell refreshCellWithDic:dict];
    return cell;
}
#pragma mark - - -- - - - 懒加载 ---- - -- - -

- (AFHTTPSessionManager*)manger{
    
    if (!_manger) {
        
        _manger = [AFHTTPSessionManager manager];
        
        _manger.responseSerializer = [AFHTTPResponseSerializer serializer];
        
        _manger.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json", nil];
    }
    
    return _manger;
    
}
- (NSMutableArray *)datasource{
    if (!_datasource) {
        _datasource = [NSMutableArray array];
    }
    return _datasource;

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
